project(libmediasoup)
include(TestBigEndian)
TEST_BIG_ENDIAN(IS_BIG_ENDIAN)

IF (NOT WIN32)
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17")
ENDIF ()

set(MAIN_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker)
set(LIB_WEBRTC_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/deps/libwebrtc)

file(GLOB fbs_files ${MAIN_DIR}/fbs/*.fbs)

execute_process(COMMAND
        ${EXECUTABLE_OUTPUT_PATH}/flatc.exe --cpp --cpp-field-case-style lower --reflect-names --scoped-enums --filename-suffix "" -o ${RELEASE_DIR}/include/FBS ${fbs_files}
        OUTPUT_STRIP_TRAILING_WHITESPACE
        ERROR_QUIET
        WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})

file(GLOB libwebrtc_SRC
        ${LIB_WEBRTC_INCLUDE_DIR}/libwebrtc/*/*.cc
        ${LIB_WEBRTC_INCLUDE_DIR}/libwebrtc/*/*/*.cc
        ${LIB_WEBRTC_INCLUDE_DIR}/libwebrtc/*/*/*/*.cc
        ${LIB_WEBRTC_INCLUDE_DIR}/libwebrtc/*/*/*/*/*.cc
)
add_library(libwebrtc ${libwebrtc_SRC})
target_compile_definitions(libwebrtc PUBLIC NOMINMAX)
if (IS_BIG_ENDIAN)
    target_compile_definitions(libwebrtc PRIVATE "MS_BIG_ENDIAN")
else ()
    target_compile_definitions(libwebrtc PRIVATE "MS_LITTLE_ENDIAN")
endif ()
## Flatbuffers
target_include_directories(libwebrtc PUBLIC ${RELEASE_DIR}/include/)
target_include_directories(libwebrtc PUBLIC ${MAIN_DIR}/include)
target_include_directories(libwebrtc PUBLIC ${LIB_WEBRTC_INCLUDE_DIR}/libwebrtc)
target_link_libraries(libwebrtc PUBLIC uv_a flatbuffers
        absl::strings
        absl::bad_optional_access
        absl::bad_variant_access
        absl::hashtablez_sampler
        absl::raw_hash_set
        absl::hash
        absl::city
        absl::low_level_hash
        absl::throw_delegate
        absl::strings_internal
        absl::raw_logging_internal
        absl::string_view
)

#查找openssl是否安装
find_package(OpenSSL QUIET)
if (OPENSSL_FOUND)
    message(STATUS "found library:${OPENSSL_LIBRARIES},ENABLE_OPENSSL defined version is ${OPENSSL_VERSION}")
    target_compile_definitions(libwebrtc PUBLIC HAVE_OPENSSL)
    target_include_directories(libwebrtc PUBLIC ${OPENSSL_INCLUDE_DIR})
    target_link_libraries(libwebrtc PUBLIC ${OPENSSL_LIBRARIES})
endif ()


message("\n=========== libwebrtc Build Configuration ===========\n")
message(STATUS "MAIN_DIR : " ${MAIN_DIR})
message(STATUS "PROJECT_INCLUDE_DIR : " ${PROJECT_INCLUDE_DIR})
message(STATUS "PROJECT_LIB_DIR : " ${PROJECT_LIB_DIR})
message(STATUS "LIB_WEBRTC_INCLUDE_DIR : " ${LIB_WEBRTC_INCLUDE_DIR})
message(STATUS "CMAKE_INSTALL_PREFIX : " ${CMAKE_INSTALL_PREFIX})


IF (CMAKE_SYSTEM_NAME MATCHES "Linux")
    add_definitions(-DMS_LIBURING_SUPPORTED)
ENDIF ()

set(mediasoup_worker_headers
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/include/Channel/ChannelNotification.hpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/include/Channel/ChannelNotifier.hpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/include/Channel/ChannelRequest.hpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/include/Channel/ChannelSocket.hpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/include/ChannelMessageRegistrator.hpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/include/DepLibSRTP.hpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/include/DepLibUV.hpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/include/DepLibWebRTC.hpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/include/DepOpenSSL.hpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/include/DepUsrSCTP.hpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/include/LogLevel.hpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/include/Logger.hpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/include/MediaSoupErrors.hpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/include/RTC/ActiveSpeakerObserver.hpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/include/RTC/AudioLevelObserver.hpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/include/RTC/BweType.hpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/include/RTC/Codecs/H264.hpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/include/RTC/Codecs/H264_SVC.hpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/include/RTC/Codecs/Opus.hpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/include/RTC/Codecs/PayloadDescriptorHandler.hpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/include/RTC/Codecs/Tools.hpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/include/RTC/Codecs/VP8.hpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/include/RTC/Codecs/VP9.hpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/include/RTC/Consumer.hpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/include/RTC/DataConsumer.hpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/include/RTC/DataProducer.hpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/include/RTC/DirectTransport.hpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/include/RTC/DtlsTransport.hpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/include/RTC/IceCandidate.hpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/include/RTC/IceServer.hpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/include/RTC/KeyFrameRequestManager.hpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/include/RTC/NackGenerator.hpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/include/RTC/Parameters.hpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/include/RTC/PipeConsumer.hpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/include/RTC/PipeTransport.hpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/include/RTC/PlainTransport.hpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/include/RTC/PortManager.hpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/include/RTC/Producer.hpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/include/RTC/RTCP/Bye.hpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/include/RTC/RTCP/CompoundPacket.hpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/include/RTC/RTCP/Feedback.hpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/include/RTC/RTCP/FeedbackItem.hpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/include/RTC/RTCP/FeedbackPs.hpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/include/RTC/RTCP/FeedbackPsAfb.hpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/include/RTC/RTCP/FeedbackPsFir.hpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/include/RTC/RTCP/FeedbackPsLei.hpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/include/RTC/RTCP/FeedbackPsPli.hpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/include/RTC/RTCP/FeedbackPsRemb.hpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/include/RTC/RTCP/FeedbackPsRpsi.hpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/include/RTC/RTCP/FeedbackPsSli.hpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/include/RTC/RTCP/FeedbackPsTst.hpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/include/RTC/RTCP/FeedbackPsVbcm.hpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/include/RTC/RTCP/FeedbackRtp.hpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/include/RTC/RTCP/FeedbackRtpEcn.hpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/include/RTC/RTCP/FeedbackRtpNack.hpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/include/RTC/RTCP/FeedbackRtpSrReq.hpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/include/RTC/RTCP/FeedbackRtpTllei.hpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/include/RTC/RTCP/FeedbackRtpTmmb.hpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/include/RTC/RTCP/FeedbackRtpTransport.hpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/include/RTC/RTCP/Packet.hpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/include/RTC/RTCP/ReceiverReport.hpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/include/RTC/RTCP/Sdes.hpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/include/RTC/RTCP/SenderReport.hpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/include/RTC/RTCP/XR.hpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/include/RTC/RTCP/XrDelaySinceLastRr.hpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/include/RTC/RTCP/XrReceiverReferenceTime.hpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/include/RTC/RateCalculator.hpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/include/RTC/Router.hpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/include/RTC/RtcLogger.hpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/include/RTC/RtpDictionaries.hpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/include/RTC/RtpHeaderExtensionIds.hpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/include/RTC/RtpListener.hpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/include/RTC/RtpObserver.hpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/include/RTC/RtpPacket.hpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/include/RTC/RtpProbationGenerator.hpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/include/RTC/RtpRetransmissionBuffer.hpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/include/RTC/RtpStream.hpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/include/RTC/RtpStreamRecv.hpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/include/RTC/RtpStreamSend.hpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/include/RTC/RtxStream.hpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/include/RTC/SctpAssociation.hpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/include/RTC/SctpDictionaries.hpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/include/RTC/SctpListener.hpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/include/RTC/SenderBandwidthEstimator.hpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/include/RTC/SeqManager.hpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/include/RTC/Shared.hpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/include/RTC/SimpleConsumer.hpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/include/RTC/SimulcastConsumer.hpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/include/RTC/SrtpSession.hpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/include/RTC/StunPacket.hpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/include/RTC/SvcConsumer.hpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/include/RTC/TcpConnection.hpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/include/RTC/TcpServer.hpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/include/RTC/Transport.hpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/include/RTC/TransportCongestionControlClient.hpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/include/RTC/TransportCongestionControlServer.hpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/include/RTC/TransportTuple.hpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/include/RTC/TrendCalculator.hpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/include/RTC/UdpSocket.hpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/include/RTC/WebRtcServer.hpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/include/RTC/WebRtcTransport.hpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/include/Settings.hpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/include/Utils.hpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/include/Worker.hpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/include/common.hpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/include/handles/SignalHandle.hpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/include/handles/TcpConnectionHandle.hpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/include/handles/TcpServerHandle.hpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/include/handles/TimerHandle.hpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/include/handles/UdpSocketHandle.hpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/include/handles/UnixStreamSocketHandle.hpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/include/lib.hpp"
)

set(mediasoup_worker_sources
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/src/Channel/ChannelNotification.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/src/Channel/ChannelNotifier.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/src/Channel/ChannelRequest.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/src/Channel/ChannelSocket.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/src/ChannelMessageRegistrator.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/src/DepLibSRTP.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/src/DepLibUV.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/src/DepLibWebRTC.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/src/DepOpenSSL.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/src/DepUsrSCTP.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/src/Logger.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/src/MediaSoupErrors.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/src/RTC/ActiveSpeakerObserver.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/src/RTC/AudioLevelObserver.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/src/RTC/Codecs/H264.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/src/RTC/Codecs/H264_SVC.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/src/RTC/Codecs/Opus.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/src/RTC/Codecs/VP8.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/src/RTC/Codecs/VP9.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/src/RTC/Consumer.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/src/RTC/DataConsumer.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/src/RTC/DataProducer.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/src/RTC/DirectTransport.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/src/RTC/DtlsTransport.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/src/RTC/IceCandidate.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/src/RTC/IceServer.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/src/RTC/KeyFrameRequestManager.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/src/RTC/NackGenerator.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/src/RTC/PipeConsumer.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/src/RTC/PipeTransport.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/src/RTC/PlainTransport.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/src/RTC/PortManager.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/src/RTC/Producer.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/src/RTC/RTCP/Bye.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/src/RTC/RTCP/CompoundPacket.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/src/RTC/RTCP/Feedback.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/src/RTC/RTCP/FeedbackPs.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/src/RTC/RTCP/FeedbackPsAfb.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/src/RTC/RTCP/FeedbackPsFir.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/src/RTC/RTCP/FeedbackPsLei.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/src/RTC/RTCP/FeedbackPsPli.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/src/RTC/RTCP/FeedbackPsRemb.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/src/RTC/RTCP/FeedbackPsRpsi.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/src/RTC/RTCP/FeedbackPsSli.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/src/RTC/RTCP/FeedbackPsTst.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/src/RTC/RTCP/FeedbackPsVbcm.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/src/RTC/RTCP/FeedbackRtp.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/src/RTC/RTCP/FeedbackRtpEcn.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/src/RTC/RTCP/FeedbackRtpNack.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/src/RTC/RTCP/FeedbackRtpSrReq.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/src/RTC/RTCP/FeedbackRtpTllei.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/src/RTC/RTCP/FeedbackRtpTmmb.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/src/RTC/RTCP/FeedbackRtpTransport.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/src/RTC/RTCP/Packet.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/src/RTC/RTCP/ReceiverReport.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/src/RTC/RTCP/Sdes.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/src/RTC/RTCP/SenderReport.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/src/RTC/RTCP/XR.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/src/RTC/RTCP/XrDelaySinceLastRr.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/src/RTC/RTCP/XrReceiverReferenceTime.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/src/RTC/RateCalculator.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/src/RTC/Router.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/src/RTC/RtcLogger.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/src/RTC/RtpDictionaries/Parameters.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/src/RTC/RtpDictionaries/RtcpFeedback.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/src/RTC/RtpDictionaries/RtcpParameters.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/src/RTC/RtpDictionaries/RtpCodecMimeType.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/src/RTC/RtpDictionaries/RtpCodecParameters.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/src/RTC/RtpDictionaries/RtpEncodingParameters.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/src/RTC/RtpDictionaries/RtpHeaderExtensionParameters.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/src/RTC/RtpDictionaries/RtpHeaderExtensionUri.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/src/RTC/RtpDictionaries/RtpParameters.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/src/RTC/RtpDictionaries/RtpRtxParameters.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/src/RTC/RtpListener.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/src/RTC/RtpObserver.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/src/RTC/RtpPacket.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/src/RTC/RtpProbationGenerator.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/src/RTC/RtpRetransmissionBuffer.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/src/RTC/RtpStream.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/src/RTC/RtpStreamRecv.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/src/RTC/RtpStreamSend.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/src/RTC/RtxStream.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/src/RTC/SctpAssociation.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/src/RTC/SctpDictionaries/SctpStreamParameters.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/src/RTC/SctpListener.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/src/RTC/SenderBandwidthEstimator.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/src/RTC/SeqManager.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/src/RTC/Shared.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/src/RTC/SimpleConsumer.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/src/RTC/SimulcastConsumer.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/src/RTC/SrtpSession.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/src/RTC/StunPacket.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/src/RTC/SvcConsumer.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/src/RTC/TcpConnection.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/src/RTC/TcpServer.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/src/RTC/Transport.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/src/RTC/TransportCongestionControlClient.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/src/RTC/TransportCongestionControlServer.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/src/RTC/TransportTuple.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/src/RTC/TrendCalculator.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/src/RTC/UdpSocket.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/src/RTC/WebRtcServer.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/src/RTC/WebRtcTransport.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/src/Settings.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/src/Utils/Crypto.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/src/Utils/File.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/src/Utils/IP.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/src/Utils/String.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/src/Worker.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/src/handles/SignalHandle.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/src/handles/TcpConnectionHandle.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/src/handles/TcpServerHandle.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/src/handles/TimerHandle.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/src/handles/UdpSocketHandle.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/src/handles/UnixStreamSocketHandle.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/src/lib.cpp"
        #"src/main.cpp"
)

IF (CMAKE_SYSTEM_NAME MATCHES "Linux")
    set(mediasoup_worker_headers ${mediasoup_worker_headers} "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/include/DepLibUring.hpp")
    set(mediasoup_worker_sources ${mediasoup_worker_sources} "${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/src/DepLibUring.cpp")
ENDIF ()

add_library(${PROJECT_NAME}
        ${mediasoup_worker_sources}
        ${mediasoup_worker_headers})

if (IS_BIG_ENDIAN)
    target_compile_definitions(${PROJECT_NAME} PRIVATE "MS_BIG_ENDIAN")
else ()
    target_compile_definitions(${PROJECT_NAME} PRIVATE "MS_LITTLE_ENDIAN")
endif ()

IF (CMAKE_SYSTEM_NAME MATCHES "Linux")
    target_compile_definitions(${PROJECT_NAME} PRIVATE _POSIX_C_SOURCE=200112 _GNU_SOURCE)
ELSEIF (CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
    set(CMAKE_SHARED_LINKER_FLAGS "-Wl,--export-dynamic")
ELSEIF (CMAKE_SYSTEM_NAME MATCHES "Windows")
    target_compile_definitions(${PROJECT_NAME} PRIVATE NOMINMAX)
    target_include_directories(${PROJECT_NAME} PRIVATE ../deps/getopt/src)
ELSE ()

ENDIF (CMAKE_SYSTEM_NAME MATCHES "Linux")

IF (UNIX)
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}  -g -gdwarf-2 -Wall -Wendif-labels -W -Wno-unused-parameter -Wall -Wextra -Wno-unused-parameter")
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}  -fPIC")
ENDIF ()

message(STATUS "CMAKE_CXX_FLAGS : " ${CMAKE_CXX_FLAGS})

IF (APPLE)
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
    set_property(TARGET ${PROJECT_NAME}
            PROPERTY XCODE_ATTRIBUTE_WARNING_CFLAGS
            -std=c++17
            PROPERTY XCODE_ATTRIBUTE_OTHER_CPLUSPLUSFLAGS
    )
ENDIF ()

file(GLOB fbs_files ${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/fbs/*.fbs)

execute_process(COMMAND
        ${EXECUTABLE_OUTPUT_PATH}/flatc.exe --cpp --cpp-field-case-style lower --reflect-names --scoped-enums --filename-suffix "" -o ${RELEASE_DIR}/include/FBS ${fbs_files}
        OUTPUT_STRIP_TRAILING_WHITESPACE
        ERROR_QUIET
        WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})

target_include_directories(${PROJECT_NAME}
        PUBLIC
        ${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/include
        ${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/deps/libwebrtc/libwebrtc
        ${CMAKE_CURRENT_SOURCE_DIR}/../ext/mediasoup/worker/deps/libwebrtc
        ${RELEASE_DIR}/include/
        ${CMAKE_CURRENT_SOURCE_DIR}/../ext/flatbuffers/include
        ${CMAKE_CURRENT_SOURCE_DIR}/../ext/abseil-cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/../ext/libsrtp/include
        ${CMAKE_CURRENT_SOURCE_DIR}/../ext/wingetopt/src
)

#查找openssl是否安装
find_package(OpenSSL QUIET)
if (OPENSSL_FOUND)
    message(STATUS "found library:${OPENSSL_LIBRARIES},ENABLE_OPENSSL defined version is ${OPENSSL_VERSION}")
    target_compile_definitions(${PROJECT_NAME} PUBLIC HAVE_OPENSSL)
    target_include_directories(${PROJECT_NAME} PUBLIC ${OPENSSL_INCLUDE_DIR})
    target_link_libraries(${PROJECT_NAME} PUBLIC ${OPENSSL_LIBRARIES})
endif ()

target_link_libraries(${PROJECT_NAME} PUBLIC  srtp2 usrsctp wingetopt libwebrtc)

install(TARGETS ${PROJECT_NAME} DESTINATION lib)
#install(FILES ${mediasoup_worker_headers} DESTINATION include/worker)


